To replace a knock sensor or not?

You should know the actual code it’s throwing for the knock sensor. Also, a decent scan tool should be able to log whether any ‘knock events’ are recorded, to further verify whether the sensor is bad. But I agree with Cougar: a bad TPS could cause this. Unfortunately there’s a lot of other things that could cause this too.